<template>
    <div class="singer-song">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <div v-for="(item, index) in list" :key="index" :title="item" class="song">
                <h3>{{ item.name }}</h3>
                <div class="singers">
                    <span v-for="(singer, i) in item.singer" :key="singer.id">
                        {{ singer.name }}
                        <span v-show="i != item.singer.length - 1">/</span>
                    </span>
                    <span v-show="item.album">
                        <span class="circle">·</span>
                        <span>{{ item.album.name }}</span>
                    </span>
                </div>
            </div>
        </van-list>
    </div>
</template>
  
<script>

export default {
    name: "SingerSong",
    props: ['singeid'],

    data() {
        return {
            list: [], // vant 的list列表数据
            loading: false,
            finished: false,
            page: 1 //获取api数据的页码
        }
    },
    created() {
        this.getData()
    },
    methods: {
        getData() {
            this.$request('get', `/singer/songs?singermid=${this.singeid}&page=${this.page}&num=20`)
                .then(res => {
                    this.list = this.list.concat(res.data.list)
                    this.loading = false
                    this.page++
                    if (res.data.list.length === 0) {
                        this.finished = true
                    }
                })


        },
        onLoad() {
            setTimeout(() => {
                this.getData();
                this.loading = true
            }, 1000);
        }
    }
}
</script>
  
<style scoped>
.song {
    margin-bottom: 1rem;
}

.song>h3 {
    text-align: left;
    font-size: 1rem;
    padding: 0 2rem;
    margin: 0;
}

.singers {
    text-align: left;
    padding: 0 2rem;

}

.singers span {
    font-size: 0.8rem;
    color: gray;
}

.singers>span:nth-last-child(1)>span:nth-child(1) {
    margin: 0 0.3rem;
    font-weight: 900;
    color: red;
}
</style>